import datetime

from tortoise import Model, fields

from .fastapi_admin.models import AbstractAdminLog, AbstractPermission, AbstractRole, AbstractUser

from .enums import ProductType, Status
from datetime import datetime

class User(AbstractUser):
    nickname = fields.CharField(max_length=30,unique=True)
    avatar = fields.CharField(max_length=200, default="http://weni09.gitee.io/picbed/avatar/2.png",
                              description="default value:http://weni09.gitee.io/picbed/avatar/2.png, may be not required")
    intro = fields.TextField(default="")
    created_at = fields.DatetimeField(auto_now_add=True)
    last_login = fields.DatetimeField(description="Last Login", default=datetime.now())
    def __str__(self):
        return f"{self.pk}#{self.username}"

    def rowVariant(self) -> str:
        if not self.is_active:
            return "warning"
        return ""

    def cellVariants(self) -> dict:
        if self.is_active:
            return {
                "intro": "info",
            }
        return {}
    class PydanticMeta:
        computed = ("rowVariant", "cellVariants")
    class Meta:
        app = "blog"
class Permission(AbstractPermission):
    """
    must inheritance AbstractPermission
    """
    class Meta:
        app = "blog"
class Role(AbstractRole):
    """
    must inheritance AbstractRole
    """
    class Meta:
        app = "blog"
class AdminLog(AbstractAdminLog):
    """
    must inheritance AbstractAdminLog
    """
    created_at = fields.DatetimeField(auto_now_add=True)
    class Meta:
        app = "blog"
